#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include "cmpcxx.h"

using namespace std;
using namespace cmpcxx;

int main() {
	// path_split and path_split_ext
	{
		cmp_title("path_split and path_split_ext");
		vector<string> arr{
			"/",
			"//",
			"///",
			"/var",
			"dir/",
			"/var/dir/",

			"/var/asuspei/backup",
			"/var/asuspei/backup/",
			"/var/asuspei/backup//",
			"/var/asuspei//backup",
			"/var/asuspei///backup",
			"/var/asuspei///backup///",
			"/var/asuspei/backup/xxx",
			"/var/asuspei/backup//xxx",
			"/var/asuspei/backup/xxx.jpeg",
			"/var/asuspei/backup///xxx.jpeg",
			"/var/asuspei/backup/xxx.tmp.jpeg",
			"/var/asuspei/backup////xxx.tmp.jpeg",

			"abc",
			"abc.txt",
			"abc.tmp.txt",
			".nomedia",
			"/.nomedia",
			"xx/.nomedia",
			"xx/yy/.nomedia",
			"/var/xx/yy/.nomedia",

			"result/pred.jpg",
			"result/pred.tmp.jpg",
			"result/pred",

			"",
		};
		for (int i = 0; i < arr.size(); ++i) {
			string str = arr[i];
			{
				string dir, base, main, ext;
				path_split(str, dir, base);
				path_split_ext(str, main, ext);
				string base_main = get_base_main_name(str);
				assert(dir == get_dir(str));
				assert(base == get_base(str));
				assert(main == get_main(str));
				assert(ext == get_ext(str));
				assert(main == path_join(dir, base_main));
				cout << "|" << str << "|:" << endl;
				cout << "dir=|" << dir << "|, base=|" << base << "|" << endl;
				cout << "main=|" << main << "|, base_main=|" << base_main << "|, ext=|" << ext << "|" << endl;
			}
		}
		cmp_newline(1);
	}

	// path_remove_tail_slash, path_remove_head_slash
	{
		cmp_title("path_remove_tail_slash, path_remove_head_slash");
		vector<string> arr{
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages///",

			"//var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/2008_000002.jpg",
			"///var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/",
			"////var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//",
			"////var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages///",

			"scripts/VOCdevkit/VOC2012/JPEGImages/2008_000003.bmp",
			"scripts/VOCdevkit/VOC2012/JPEGImages/",
			"scripts/VOCdevkit/VOC2012/JPEGImages//",
			"scripts/VOCdevkit/VOC2012/JPEGImages///",

			"JPEGImages/2008_000003.png",
			"JPEGImages",
			"JPEGImages/",
			"JPEGImages//",
			"JPEGImages///",

			"",
			"/",
			"//",
			"///"
		};
		for (int i = 0; i < arr.size(); ++i) {
			string str = arr[i];
			cout << "ORIG: |" << str << "| (ORIG)" << endl;
			cout << "RMTS: |" << path_remove_tail_slash(str) << "| (RMTS)" << endl;
			cout << "RMHS: |" << path_remove_head_slash(str) << "| (RMHS)" << endl;
		}
		cmp_newline(1);
	}

	// path_join
	{
		cmp_title("path_join");
		vector<string> arr{
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages", "2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/", "2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//", "2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages", "/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/", "//2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//", "///2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages", "2008_000002.jpg",

			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/", "xx/yy/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//", "xx/yy/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages", "/xx/yy/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages/", "//xx/yy/2008_000002.jpg",
			"/var/asuspei/my_svn/c_darknet/darknet-debug-cpu/scripts/VOCdevkit/VOC2012/JPEGImages//", "///xx/yy/2008_000002.jpg",

			"", "",
			"", "/",
			"", "a.png",
			"/", "",
			"dir", "",
			"dir", "b.bmp",

			"/", "/",
			"//", "//",
			"//", "//a.png",
			"dir//", "//",
			"dir//", "//b.bmp"
		};
		for (int i = 0; i < arr.size(); i += 2) {
			string str1 = arr[i], str2 = arr[i + 1];
			string joined = path_join(str1, str2);
			cout << "|" << str1 << "| + |" << str2 << "| => |" << joined << "|" << endl;
		}
		cmp_newline(1);
	}

	return 0;
}
